// 通用类型定义
export interface ApiResponse<T = any> {
  success: boolean
  code: string
  message: string
  data: T
}

export interface PageRequest {
  page: number
  size: number
}

export interface PageResponse<T> {
  list: T[]
  total: number
  pageSize: number
  page: number
  totalPages: number
}

// 用户相关类型

export interface User {
  id: number
  username: string
  nickname?: string
  phone: string
  email: string
  status: number
  role: string
  createTime?: string
  updateTime?: string
}

export interface LoginRequest {
  username: string
  password: string
}

export interface LoginResponse {
  accessToken: string
  refreshToken: string
}


export interface RegisterRequest {
  username: string
  password: string
  phone: string
  email: string
}

export interface UpdateUserRequest {
  nickname?: string
  phone?: string
  email?: string
}

// 修改密码请求类型 (虽然接口文档中没有，但代码中需要)
export interface ChangePasswordRequest {
  oldPassword: string
  newPassword: string
  confirmPassword: string
}

// 商品相关类型
export interface Product {
  id: number
  name: string
  description: string
  imageUrl: string
  point: number
  categoryId: number
  isHot: boolean
  status: number
  startTime: string
  endTime: string
  stock: number
  createTime?: string
  updateTime?: string
}

export interface Category {
  id: number
  name: string
  parentId: number
  level: number
  sort: number
  icon: string
  description: string
  status: number
  createTime: string
  updateTime: string
}

export interface ProductSearchRequest {
  keyword?: string
  categoryId?: number
  minPoints?: number
  maxPoints?: number
  isHot?: boolean
  status?: number
  startTime?: string
  endTime?: string
  sortField?: string
  sortOrder?: string
  page?: number
  size?: number
}

export interface ProductSearchResponse {
  products: Product[]
  total: number
  categories: Category[]
  pointRanges: Record<string, number>
}

// 订单相关类型
export interface OrderItem {
    productId: number;
    productName: string;
    productImageUrl: string;
    points: number;
    quantity: number;
}

export interface Order {
  id: number
  orderNo: string
  userId: number
  totalPoints: number
  status: 'CREATING' | 'PENDING' | 'PAID' | 'CANCELLED' | 'SHIPPED' | 'COMPLETED' | 'REFUNDING' | 'REFUNDED' | 'TIMEOUT' | 'FAILED'
  receiverName: string
  receiverPhone: string
  receiverAddress: string
  remark: string
  createdTime: string
  items: OrderItem[]
}

export interface OrderItemCreateDTO {
    productId: number;
    quantity: number;
}

export interface CreateOrderRequest {
    userId: number
    remark?: string;
    items: OrderItemCreateDTO[];
}

export interface CancelOrderRequest {
  orderId: number
  userId: number
  points: number
}

// 积分相关类型
export interface PointsAccount {
  id: number
  userId: number
  totalPoints: number
  totalIncomePoints: number
  totalOutcomePoints: number
  frozenPoints: number
  updatedTime: string
}

export interface PointsRecord {
  id: number
  userId: number
  recordType: string
  changeAmount: number
  type: string
  description: string
  createdTime: string
}

export interface PointOperateRequest {
  userId: number
  orderId?: number
  amount?: number
  recordType: 'INCOME' | 'OUTCOME' | 'FREEZE' | 'UNFREEZE' | 'DEDUCT_FROZEN'
  sourceType?: 'SIGN_IN' | 'REGISTER' | 'PURCHASE' | 'INVITE' | 'ACTIVITY' | 'COMPENSATE' | 'ORDER_CREATE' | 'ORDER_PAY' | 'ORDER_CANCEL' | 'EXCHANGE' | 'REFUND' | 'SYSTEM_ADJUST' | 'SYSTEM_DEDUCT'
  desc?: string
}

// 地址相关类型
export interface Address {
  id: number
  receiverName: string
  phone: string
  province: string
  city: string
  district: string
  detailAddress: string
  isDefault: number // 0-否，1-是
}

export interface DashboardStats {
    userCount: number;
    orderCount: number;
    pendingOrderCount: number;
    totalPointsSpent: number;
}

export interface CreateAddressRequest {
  receiverName: string
  phone: string
  province: string
  city: string
  district: string
  detailAddress: string
  isDefault?: number // 0-否，1-是
}

// 购物车相关类型
export interface CartItemVO {
    productId: number;
    name: string;
    imageUrl: string;
    quantity: number;
    points: number;
    selected: boolean;
    stock: number;
}

export interface CartVO {
    items: CartItemVO[];
    totalItems: number;
    totalPoints: number;
}

export interface CartAddDTO {
    productId: number;
    quantity: number;
}


// 路由元信息类型
export interface RouteMeta {
  requiresAuth?: boolean
  requiresGuest?: boolean
  title?: string
  icon?: string
}
